{{- if .Values.userAuthz.enableMultiTenancy }}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: user-authz-webhook
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "user-authz-webhook")) | nindent 2 }}
data:
  config.json: |
    { "crds": {{ .Values.userAuthz.internal.clusterAuthRuleCrds | toJson}} }
{{- else }}
  {{- range $crd := .Values.userAuthz.internal.clusterAuthRuleCrds }}
    {{- if hasKey $crd.spec "allowAccessToSystemNamespaces" }}
      {{- fail "You must turn on userAuthz.enableMultiTenancy to use allowAccessToSystemNamespaces flag in your ClusterAuthorizationRule resources." }}
    {{- end }}
    {{- if hasKey $crd.spec "limitNamespaces" }}
      {{- fail "You must turn on userAuthz.enableMultiTenancy to use limitNamespaces option in your ClusterAuthorizationRule resources." }}
    {{- end }}
    {{- if hasKey $crd.spec "namespaceSelector" }}
      {{- fail "You must turn on userAuthz.enableMultiTenancy to use namespaceSelector option in your ClusterAuthorizationRule resources." }}
    {{- end }}
  {{- end }}
{{- end }}
